export default {
  data() {
    return {
      id: null,
      finishedText: '没有更多了',
      loading: false,
      finished: false,
      pageNo: 0,
      pageSize: 10
    }
  },
  created() {
    this.getId()
  },
  methods: {
    noPay() {
      this.$dialog.alert({
        title: '提示',
        message: '由于电脑版无法支付，请在手机上进行报名操作'
      })
    },
    isPcWx() {
      let ua = navigator.userAgent.toLowerCase()
      if (ua.indexOf('windowswechat') > -1 || ua.indexOf('macwechat') > -1) {
        this.noPay()
        return true
      } else {
        return false
      }
    },
    getId() {
      let params = this.$route.params
      if (params && params.id) {
        this.id = params.id
      }
    },
    addResData(res) {
      this.list = this.list.concat(res)
      if (res.length < this.pageSize) {
        this.finished = true
      }
      this.loading = false
    },
    compare(propertyName) {
      return function (obj1, obj2) {
        let val1 = obj1[propertyName]
        let val2 = obj2[propertyName]
        if (val2 > val1) {
          return -1
        } else if (val2 < val1) {
          return 1
        } else {
          return 0
        }
      }
    }
  },
  beforeRouteLeave(to, from, next) {
    let lastIndex = this.$route.path.lastIndexOf('/')
    let name = ''
    if (lastIndex) {
      name = this.$route.path.split('/')[1]
    } else {
      name = this.$route.path.replace('/', '')
    }
    if (to.meta.level < from.meta.level) {
      this.$store.commit('addNoCache', name)
      // console.log('后退')
    } else {
      this.$store.commit('removeNoCache', name)
      // console.log('前进')
    }
    next()
  }
}